﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Xceed.Words.NET;
namespace WordSet
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Enabled = false;
            foreach(var item in listBox1.Items)
            {
                using (DocX document = DocX.Load(item.ToString()))
                {
                    document.AddHeaders();
                    document.AddFooters();
                    Headers headers = document.Headers;
                    
                    Paragraph h1 = headers.Even.InsertParagraph();
                    Paragraph h2 = headers.Odd.InsertParagraph();
                    Footers footers = document.Footers;
                    Paragraph f1 = footers.Even.InsertParagraph();
                    Paragraph f2 = footers.Odd.InsertParagraph();
                    h1.Append(textBox1.Text);
                    h2.Append(textBox1.Text);
                    f1.Append(textBox2.Text);
                    f2.Append(textBox2.Text);
                    document.Save();
                }
                listBox2.Items.Add(item);
               
            }
            listBox1.Enabled = true;
            listBox1.Items.Clear();
        }

        private void listBox1_DragOver(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.All;

        }

        private void listBox1_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
            {
                String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
                foreach (String s in files)
                {
                    if(s.ToLower().IndexOf("docx")>0)
                    (sender as ListBox).Items.Add(s);
                }
             }
        }

        private void listBox1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.All;
        }
    }
}
